<template>
  <div class>
    <el-container>
      <el-header>
        <h2>电商后台管理系统</h2>
        <el-button type="info" style="height:40px;margin-top:10px;" @click="open">退出</el-button>
      </el-header>

      <el-container>
        <el-aside :width="isCollapse ? '60px' : '200px'">
          <div class="collapse-button" @click="isCollapse = !isCollapse">|||</div>
          <el-menu
            router
            :collapse-transition="false"
            :collapse="isCollapse"
            unique-opened
            :default-active="$route.path"
            class="el-menu-vertical-demo"
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409eff"
          >
            <el-submenu :index="item.path" v-for="(item,index) in asideArr" :key="item.id">
              <template slot="title">
                <i :class="icon[index]"></i>
                <span>{{item.authName}}</span>
              </template>

              <el-menu-item-group v-for="(it) in asideArr[index].children" :key="it.id">
                <el-menu-item :index="it.path">
                  <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>{{it.authName}}</span>
                  </template>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { getMenuApi } from "@/http/api";
export default {
  data() {
    return {
      isCollapse: false,
      asideArr: [],
      icon: [
        "el-icon-user-solid",
        "el-icon-s-tools",
        "el-icon-s-goods",
        "el-icon-s-claim",
        "el-icon-s-data"
      ]
    };
  },
  created() {
    this.getMenus();
  },
  mounted() {},
  methods: {
    getMenus() {
      getMenuApi().then(res => {
        console.log(res);
        this.asideArr = res;
      });
    },
    open() {
      this.$confirm("您确认取消登录吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          sessionStorage.removeItem("token");
          this.$router.push("/");
          this.$message({
            type: "success",
            message: "退出成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    }
  },

  computed: {},
  components: {},
  watch: {}
};
</script>

<style lang='scss'>
.el-header {
  display: flex;
  justify-content: space-between;
  background-color: #373d41;
  color: #fff;
  text-align: center;
  line-height: 15px;
}

.el-aside {
  background-color: rgb(51, 55, 68);
  color: #fff;
  // text-align: center;
  height: 100vh;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  // text-align: center;
  // line-height: 160px;
}

.collapse-button {
  text-align: center;
  cursor: pointer;
}
</style>

